package com.itheima;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.dao.UserDao;
import com.itheima.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SpringBootTest
public class MybatisBeach {

    @Autowired
    private UserDao userDao;

    @Test
    void test01() {

        // 批量删除
        ArrayList<Long> list = new ArrayList<>();

        list.add(7L);
        list.add(8L);

        int i = userDao.deleteBatchIds(list);
        System.out.println("是否删除成功 :  " + i);


    }

    @Test
    void test02() {
        // 批量查询
        ArrayList<Long> list = new ArrayList<>();

        list.add(2L);
        list.add(3L);

        List<User> ids = userDao.selectBatchIds(list);
        System.out.println(ids);

        // 方案 2

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.in("id", ids);
        List<User> list1 = userDao.selectList(wrapper);
        System.out.println(list1);


    }

    @Test
    void test03() {
        // 根据密码 进行分组
        QueryWrapper<User> wrapper = new QueryWrapper<>();

        wrapper.select("password", "count(*) count");

        wrapper.groupBy("password");

        List<Map<String, Object>> maps = userDao.selectMaps(wrapper);

        for (Map<String, Object> map : maps) {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
        }
    }


}
